const rootFontSize = 100; // 默认字体大小
// update font size of root when window resize
function setHtmlFont() {
  const docEl = document.documentElement;
  const dpr = window.devicePixelRatio || 1;

  // adjust body font size
  function setBodyFontSize() {
    if (document.body) {
      document.body.style.fontSize = `${16 * dpr}px`;
    } else {
      document.addEventListener("DOMContentLoaded", setBodyFontSize);
    }
  }
  setBodyFontSize();
  function setRemUnit() {
    let rem = 16;
    rem = (docEl.offsetWidth / 750) * 100;
    docEl.style.fontSize = `${rem}px`;
  }
  setRemUnit();
  // reset rem unit on page resize
  window.addEventListener("resize", setRemUnit);
  window.addEventListener("pageshow", (e) => {
    if (e.persisted) {
      setRemUnit();
    }
  });
}
setHtmlFont();
